goog.provide('dkpoints');
goog.provide('dkpoints.App');

goog.require('dkpoints.ServiceProvider');
goog.require('dkpoints.auth.Auth');
goog.require('dkpoints.menu.Menu');
goog.require('dkpoints.nav.Nav');
goog.require('dkpoints.rpc.RPCService');
goog.require('dkpoints.status.Status');

goog.require('goog.dom');



/**
 * The Singleton Application class.
 * @constructor
 */
dkpoints.App = function() {
  // Set up local variables to avoid multiple property lookups.
  var rpc, menu, auth, status, serviceProvider;

  var body = /** @type {!Element} */ (document.body),
      bodyContent = goog.dom.getElement('body_content');

  if (goog.isNull(bodyContent)) {
    throw Error('Missing body_content element in host page.');
  }
  var menuContent = goog.dom.getElement('menu_content');
  if (goog.isNull(menuContent)) {
    throw Error('Missing menu_content element in host page.');
  }

  rpc = new dkpoints.rpc.RPCService();
  menu = new dkpoints.menu.Menu(menuContent);
  status = new dkpoints.status.Status(body, bodyContent);

  auth = new dkpoints.auth.Auth(rpc, menu, status);
  auth.init();

  /**
   * @type {dkpoints.ServiceProvider}
   * @private
   */
  this.serviceProvider_ = serviceProvider =
      new dkpoints.ServiceProvider(auth, rpc, status, bodyContent);

  /**
   * @type {dkpoints.nav.Nav}
   * @private
   */
  this.nav_ = new dkpoints.nav.Nav(serviceProvider);

  /**
   * @type {dkpoints.App}
   * @private
   */
  dkpoints.app_ = this;
};
goog.exportSymbol('App', dkpoints.App);


/**
 * Gets the running dkpoints.App instance.
 * @return {dkpoints.App} Returns the running application instance.
 */
dkpoints.getApp = function() {
  return dkpoints.app_;
};
